/**
 * \file   iirfilter.h
 *         Implements a IIR filter
 * \author Manuel Leiva , Esteban Zu?iga, Jorge Hidalgo
 * \date   2012.03

 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 *
 * $Id: iirfilter.h $
 */

#ifndef IIRFILTER_H
#define IIRFILTER_H

#include "rom.h"

class iirfilter {

public:

    /* Struct that dinamically holds IIR coefficients */
    struct tIirMainStructure  {
        float coefs_xn[4];
        float coefs_yn[3];
    }coefficients;

    iirfilter();
    ~iirfilter();

    /* Init the filter operation */
    void init(tIirMainStructure* coefss);

    /* Filter the in buffer and leave the result in out */
    void filter(int blockSize, float* in, float* out, tIirMainStructure coefss);

    /* Reset the filter */
    void reset(tIirMainStructure coefss);

protected:

    /*
     * Ring buffer output and input.
     * This will have a 2^n size to facilitate the modulo computation
     */
    float* ringBuffer_out;
    float* ringBuffer_in;

    /* Temporal buffer */
    float *out_tmp;

    /* Ring buffer size */
    int ringBufferSize_i;
    int ringBufferSize_o;

    /* Ring Buffer Index */
    int idx_out,idx_in;
};

#endif // IIRFILTER_H
